<template>
    <div class="btn-like" @click="onClick">
        <div class="icon">
            <img
                v-if="isLike"
                :src="require('@/assets/icon/like_active.png')"
            />
            <img v-else :src="require('@/assets/icon/like.png')" />
        </div>
        <div class="text">
            <span v-if="likes && likes.length > 0">{{ likes.length }}</span>
        </div>
    </div>
</template>

<script>
import { debounce } from "@/utils/tools";
export default {
    props: {
        likes: Array
    },
    data() {
        return {};
    },

    computed: {
        userId() {
            return this.$store.state.userInfo.uid;
        },
        isLike() {
            let isLike = this.likes.find(c => {
                return c.uid === this.userId;
            });

            return isLike;
        }
    },

    methods: {
        onClick: debounce(function() {
            console.log("点赞列表", this.likes);

            if (!this.isLike) {
                this.$emit("like-click");
            } else {
                this.$showToast("你已经点赞过了");
            }
        })
    }
};
</script>


<style lang="less" scoped>
.btn-like {
    text-align: center;
    color: #666;

    .text {
        line-height: 28px;
        min-height: 28px;
        font-size: 28px;
    }
}
</style>